//
//  EnterCostDetailVC.m
//  KuWoCan
//
//  Created by hwd on 17/4/12.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "EnterCostDetailVC.h"
#import "DoubleLabCell.h"
#import "BottomDoubleBtnView.h"
#import "NWSaleApplyRequest.h"
#import "EnterCostListModel.h"
#import "CargoCell.h"
#import "PhotoManageCell.h"
#import "NWPicManageRequest.h"
#import "LabTextViewCell.h"

#import "EnterCostCommitVC.h"
#import "EnterCostListModel.h"

#import "CargoCell.h"
#import "PDDetailModel.h"


@interface EnterCostDetailVC ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
{
    BottomDoubleBtnView *btnsView;
}

@property (nonatomic,strong) NSArray *detailInfoArr;

@property (nonatomic,strong) NSArray *recordListArr; //审批信息数组

@property (nonatomic,strong) EnterCostListModel *detailModel;

@property (nonatomic,strong) UITableView *tabView;

@property (nonatomic,strong) UIAlertView *deleteAlert;

@property (nonatomic,strong) NSMutableArray<PicListModel *> *scenePics; //进场照片数组

@property (nonatomic,strong) NSMutableArray *paperPics; //票据照片数组

@property (nonatomic,assign) SAQueryStatus orderStatus;

@property (nonatomic,strong) NSMutableArray *cargoListArr;

@property (nonatomic,assign)BOOL isNeedHXBZ;//是否需要核销标准
@property (nonatomic,assign)BOOL isShowHXBZ;//是否展示核销标准
@property (nonatomic,strong)NSMutableArray *DataHXBZArr;//核销标准数组
@property (nonatomic,assign)NSInteger tagNumber;//核销标准按钮点击tag值
@property (nonatomic,strong)NSString *mbContect;//核销标准的内容
@property (nonatomic,strong)UIButton *deleteBtn;

@end

@implementation EnterCostDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    if (self.moduleType == HomeModuleTypeEA) {
        self.title = @"进场费用详情";
    } else {
        self.title = @"进场费用核销详情";
    }
    _cargoListArr = [[NSMutableArray alloc]init];
    [self getData];
}

- (void)getData
{
    NWSaleApplyRequest *request = [[NWSaleApplyRequest alloc] init];
    if (_moduleType == HomeModuleTypeEA)
    {
        [request startRequestEnterApplyDetailWithId:_orderId];
    }
    else if (_moduleType == HomeModuleTypeEC)
    {
        [request startRequestEnterCheckDetailWithId:_orderId];
    }
    [request completion:^(id result, NSString *message, id extension, BOOL succ) {
        if (succ)
        {
            //这里做数据解析
            _detailModel = [[EnterCostListModel alloc] initWithDictionary:result[@"data"] error:nil];
            _recordListArr = [EnterDetailCheckListModel arrayOfModelsFromDictionaries:_detailModel.approvalList];

            if (_moduleType == HomeModuleTypeEC)
            {
                _scenePics = _detailModel.scenePhotoList.copy;
                _paperPics = _detailModel.paperPhotoList.copy;
                _orderStatus = [_detailModel.examineStatus integerValue];
            }
            else
            {
                _scenePics = _detailModel.photoList.mutableCopy;
                _orderStatus = [_detailModel.approvalStatus integerValue];
            }

            
           _detailInfoArr = @[@{@"渠道名称":[ToolViewViewController GetDataStr:_detailModel.name]},@{@"渠道说明":[ToolViewViewController GetDataStr:_detailModel.supermarketProfiles]},@{@"地址":[ToolViewViewController GetDataStr:_detailModel.address]},@{@"手机号码":[ToolViewViewController GetDataStr:_detailModel.phone]},@{@"办公电话":[ToolViewViewController GetDataStr:_detailModel.workPhone]},@{@"负责人":[ToolViewViewController GetDataStr:_detailModel.purchase]},@{@"门店数量":[ToolViewViewController GetDataStr:_detailModel.storeNumber]},@{@"年经营额":[ToolViewViewController GetDataStr:_detailModel.annualOperation]},@{@"同类品牌":[ToolViewViewController GetDataStr:_detailModel.similarBrands]},@{@"年销售额":[ToolViewViewController GetDataStr:_detailModel.annualSales]},@{@"费用总计":[ToolViewViewController GetDataStr:_detailModel.totalExpenses]},@{@"费用说明":[ToolViewViewController GetDataStr:_detailModel.costStatement]}];

            if (_moduleType == HomeModuleTypeEC)
            {
                _cargoListArr =  _detailModel.kwApproachExamineProduct.copy;
            }
            else
            {
                _cargoListArr =  _detailModel.kwApproachApplicationProduct.copy;
            }
           
            NSLog(@"SADetailSBCargoModel========%@",_cargoListArr);
            if ([_detailModel.approverUser isEqualToString:[Singleton shareInstance].userId] && _moduleType == HomeModuleTypeEA)//选择核销标准
            {
                _isNeedHXBZ = _orderStatus == SAQueryStatusToAudit?YES:NO;
            }
        
            
            _isShowHXBZ = result[@"data"][@"mbContent"]?YES:NO;
            _mbContect = result[@"data"][@"mbContent"]?result[@"data"][@"mbContent"]:@"未填写";
            

            if(_isNeedHXBZ){
                [self addGetHeXiaoMessage];
            }else{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self setUpUI];
                });
            }

        } else {
            [SVProgressHUD showErrorWithStatus:message];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    }];
}
-(void)addGetHeXiaoMessage//有权限审批 且 待审批状态
{
    //1 进场费  2 陈列费  3 促销活动
    [HttpRequest PostrequestUrl:[NSString stringWithFormat:@"%@/jeesite/interface/kwMoban/list",baseUrlMe] Dic:@{@"mbType":@"1"} completion:^(NSDictionary *responseDic) {
        if ([responseDic[@"success"] boolValue]){
            _DataHXBZArr = [[NSMutableArray alloc]initWithArray:responseDic[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self setUpUI];
            });
        }else
        {
            [ToolViewViewController addPopAlterViewController:responseDic[@"msg"]?responseDic[@"msg"]:@"" Controller:self];
        }
    }];
}
- (void)reloadData {
    NWSaleApplyRequest *request = [[NWSaleApplyRequest alloc] init];
    if (_moduleType == HomeModuleTypeEA)
    {
        [request startRequestEnterApplyDetailWithId:_orderId];
    }
    else if (_moduleType == HomeModuleTypeEC)
    {
        [request startRequestEnterCheckDetailWithId:_orderId];
    }
    [request completion:^(id result, NSString *message, id extension, BOOL succ) {
        if (succ)
        {
            //这里做数据解析
            _detailModel = [[EnterCostListModel alloc] initWithDictionary:result[@"data"] error:nil];
            _recordListArr = [EnterDetailCheckListModel arrayOfModelsFromDictionaries:_detailModel.approvalList];

            if (_moduleType == HomeModuleTypeEC)
            {
                _scenePics = _detailModel.scenePhotoList.copy;
                _paperPics = _detailModel.paperPhotoList.copy;
                _orderStatus = [_detailModel.examineStatus integerValue];
            }
            else
            {
                _scenePics = _detailModel.photoList.mutableCopy;
                _orderStatus = [_detailModel.approvalStatus integerValue];
            }

            _detailInfoArr = @[@{@"渠道名称":[ToolViewViewController GetDataStr:_detailModel.name]},@{@"渠道说明":[ToolViewViewController GetDataStr:_detailModel.supermarketProfiles]},@{@"地址":[ToolViewViewController GetDataStr:_detailModel.address]},@{@"手机号码":[ToolViewViewController GetDataStr:_detailModel.phone]},@{@"办公电话":[ToolViewViewController GetDataStr:_detailModel.workPhone]},@{@"负责人":[ToolViewViewController GetDataStr:_detailModel.purchase]},@{@"门店数量":[ToolViewViewController GetDataStr:_detailModel.storeNumber]},@{@"年经营额":[ToolViewViewController GetDataStr:_detailModel.annualOperation]},@{@"同类品牌":[ToolViewViewController GetDataStr:_detailModel.similarBrands]},@{@"年销售额":[ToolViewViewController GetDataStr:_detailModel.annualSales]},@{@"费用总计":[ToolViewViewController GetDataStr:_detailModel.totalExpenses]},@{@"费用说明":[ToolViewViewController GetDataStr:_detailModel.costStatement]}];
            

            
            if (_moduleType == HomeModuleTypeEC)
            {
                _cargoListArr =  _detailModel.kwApproachExamineProduct.copy;
            }
            else
            {
                _cargoListArr =  _detailModel.kwApproachApplicationProduct.copy;
            }

            if ([_detailInfoModel.approverUser isEqualToString:[Singleton shareInstance].userId])//选择核销标准
            {
                _isNeedHXBZ = _orderStatus == SAQueryStatusToAudit?YES:NO;
            }
          
            _isShowHXBZ = result[@"data"][@"mbContent"]?YES:NO;
            _mbContect = result[@"data"][@"mbContent"]?result[@"data"][@"mbContent"]:@"未填写";
            

            [self.tabView reloadData];
        } else {
            [SVProgressHUD showErrorWithStatus:message];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    }];
}


//修改按钮,先判断是否是自己的订单
//如果是自己订单,待提交  待审批状态下  有修改按钮
- (void)createChangeBtn
{
    if ([[Singleton shareInstance].userType integerValue] == UserTypeAgency)
    {
        if ([_detailModel.userId isEqualToString:[Singleton shareInstance].userId])
        {
            if (_orderStatus == SAQueryStatusToSubmit || _orderStatus == SAQueryStatusToAudit)
            {
                [self createRightButton:@"修改" selector:@selector(changeInfo)];
            }
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)changeInfo
{
    EnterCostCommitVC *vc = [[EnterCostCommitVC alloc] init];
    vc.isChangeInfo = YES;
    vc.detailInfoModel = _detailModel;
    vc.orderId = _orderId;
    vc.orderStatus = [NSString stringWithFormat:@"%zd", _orderStatus];
    vc.moduleType = _moduleType;
    vc.isShowHXBZ = _isShowHXBZ;
    vc.mbContect = _mbContect;
    vc.submitComplete = ^{
        [self reloadData];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)createBottomView
{
    //这里创建底部操作按钮,先要判断是否是本人的订单,如果是在判断自己的身份,显示对应按钮
    //是本人订单
    //根据订单状态来显示底部按钮
    if ([[Singleton shareInstance].userType integerValue] == UserTypeAgency)
    {
        if ([_detailModel.userId isEqualToString:[Singleton shareInstance].userId])
        {
            if (_moduleType == HomeModuleTypeEA)
            {
                if (_orderStatus == SAQueryStatusToAudit || _orderStatus == SAQueryStatusToSubmit)
                {
                    [self createBottomBtnWithTitle:@"删除"];
                }
                else if (_orderStatus == SAQueryStatusCompleted)
                {
                    [self createBottomBtnWithTitle:@"确认查看"];
                }
                else
                {
                    [_tabView mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.bottom.equalTo(@0);
                    }];
                }
            }
            else
            {
                if (_orderStatus == SAQueryStatusToSubmit) {
                    [self createSubmitButton];
                } else {
                    [_tabView mas_updateConstraints:^(MASConstraintMaker *make) {
                        make.bottom.equalTo(@0);
                    }];
                }
            }

        }
    }
    else
    {
        if ([_detailModel.approverUser isEqualToString:[Singleton shareInstance].userId])
        {
            if(_orderStatus == SAQueryStatusToAudit)
            {
                [self createDoubleBtnsView];
            }
            else if (_orderStatus == SAQueryStatusAuditting || _orderStatus == SAQueryStatusPlanningDepartment || _orderStatus == SAQueryStatusMarketingCenter)
            {
                [self createDoubleBtnsView];
            }
            else
            {
                [_tabView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.bottom.equalTo(@0);
                }];
            }
        }
        else
        {
            [_tabView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(@0);
            }];
        }
    }
}

- (void)createBottomBtnWithTitle:(NSString *)title
{
    _deleteBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [_deleteBtn setBackgroundColor:KwBlueColor];
    [_deleteBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_deleteBtn setTitle:title forState:UIControlStateNormal];
    _deleteBtn.titleLabel.font = KwFont(16.0);
    [_deleteBtn addTarget:self action:@selector(deleteOrder:) forControlEvents:UIControlEventTouchUpInside];
    _deleteBtn.layer.masksToBounds = YES;
    _deleteBtn.layer.cornerRadius = 5.0;
    [self.view addSubview:_deleteBtn];
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-5);
        make.top.equalTo(_tabView.mas_bottom).offset(1);
        make.left.equalTo(@5);
        make.right.equalTo(@-5);
    }];
}

- (void)createSubmitButton {
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [confirmBtn setBackgroundColor:KwBlueColor];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmBtn setTitle:@"提交" forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = KwFont(16.0);
    [confirmBtn addTarget:self action:@selector(submitOrder) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.layer.masksToBounds = YES;
    confirmBtn.layer.cornerRadius = 5.0;
    [self.view addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-5);
        make.top.equalTo(_tabView.mas_bottom).offset(1);
        make.left.equalTo(@5);
        make.right.equalTo(@-5);
    }];
}

- (void)createDoubleBtnsView
{
    //拒绝  通过
    btnsView = [[BottomDoubleBtnView alloc] init];
    btnsView.orderId = _orderId;
    btnsView.orderStatus = [NSString stringWithFormat:@"%zd",_orderStatus];
    btnsView.moduleType = _moduleType;
    btnsView.mbContent = _DataHXBZArr.count>=_tagNumber+1?(_DataHXBZArr[_tagNumber][@"contents"]?_DataHXBZArr[_tagNumber][@"contents"]:@""):@"";
    [self.view addSubview:btnsView];
    [btnsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-5);
        make.height.equalTo(@54);
        make.left.equalTo(@5);
        make.right.equalTo(@-5);
    }];
}

- (void)deleteOrder:(UIButton *)btn
{
    if ([btn.titleLabel.text isEqualToString:@"确认查看"]) {
        [HttpRequest PostrequestUrl:[NSString stringWithFormat:@"%@/jeesite/interface/appApproachApplication/userConfirm",baseUrlMe] Dic:@{@"id":[ToolViewViewController isNotNullStr:_orderId]?_orderId:@"",@"approvalStatus":@"6"} completion:^(NSDictionary *responseDic) {
            if ([responseDic[@"success"] boolValue]) {
                [_deleteBtn removeFromSuperview];
                [self getData];
            }else
            {
                [SVProgressHUD showErrorWithStatus:@"确认失败"];
            }
            
        }];
    }else
    {
        _deleteAlert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确定删除？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [_deleteAlert show];
    }
  
}

- (void)submitOrder {
    NWSaleApplyRequest *request = [[NWSaleApplyRequest alloc] init];
    //    startRequestPassApplyOrCheckWithId

    NSMutableDictionary *paramete = [NSMutableDictionary dictionary];
    [paramete setObject:_orderId forKey:@"id"];
    [paramete setObject:[Singleton shareInstance].userId forKey:@"user.id"];
    [paramete setObject:_detailModel.name forKey:@"name"];
    [paramete setObject:_detailModel.address forKey:@"address"];
    [paramete setObject:_detailModel.phone forKey:@"phone"];
    [paramete setObject:_detailModel.purchase forKey:@"purchase"];
    [paramete setObject:_detailModel.storeNumber forKey:@"storeNumber"];
    [paramete setObject:_detailModel.annualOperation forKey:@"annualOperation"];
    [paramete setObject:_detailModel.similarBrands forKey:@"similarBrands"];
    [paramete setObject:_detailModel.annualSales forKey:@"annualSales"];
    [paramete setObject:_detailModel.totalExpenses forKey:@"totalExpenses"];
    [paramete setObject:@"1" forKey:@"examineStatus"];
    [paramete setObject:@"0" forKey:@"approvalType"];
    NSMutableArray *scenePhotoList = [NSMutableArray array];
    NSMutableArray *paperPhotoList = [NSMutableArray array];

    [_detailModel.scenePhotoList enumerateObjectsUsingBlock:^(PicListModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [scenePhotoList addObject:obj.toDictionary];
    }];

    [_detailModel.paperPhotoList enumerateObjectsUsingBlock:^(PicListModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [paperPhotoList addObject:obj.toDictionary];
    }];
    
    [paramete setObject:[CommonTool beJsonStrWithObj:scenePhotoList] forKey:@"scenePhotoList"];
    [paramete setObject:[CommonTool beJsonStrWithObj:paperPhotoList] forKey:@"paperPhotoList"];

    [request startRequestUpdateEnterCheckWithDic:paramete];
    [request completion:^(id result, NSString *message, id extension, BOOL succ) {
        if (succ) {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView == _deleteAlert)
    {
        if (buttonIndex == 1)
        {
            NWSaleApplyRequest *request = [[NWSaleApplyRequest alloc] init];
            [request startRequestDeleteApplyOrCheckWithId:_orderId moduleType:_moduleType];
            [request completion:^(id result, NSString *message, id extension, BOOL succ) {
                if (succ)
                {
                    [SVProgressHUD showSuccessWithStatus:@"删除成功"];
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }];
        }
    }
}

- (void)setUpUI
{
    [self createChangeBtn];


    //创建列表
    _tabView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
    _tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tabView.estimatedRowHeight = 40.0;
    _tabView.rowHeight = UITableViewAutomaticDimension;
    _tabView.delegate = self;
    _tabView.dataSource = self;
    [self.view addSubview:_tabView];
    [_tabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.right.equalTo(@0);
        make.bottom.equalTo(@-55);
    }];

    [self createBottomView];
}

#pragma mark tableViewDelegate,DataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_moduleType == HomeModuleTypeEA)
    {
        if (_isNeedHXBZ || _isShowHXBZ) {//展示或选择核销标准
            return 5;
        }
        return 4;
    }
    else
    {
        if (_isNeedHXBZ || _isShowHXBZ) {//展示核销标准
            return 6;
        }
        return 5;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return _detailInfoArr.count;
    }
    else if (section == 1)
    {
        if ([_detailModel.approvalType integerValue] == 1) {
            return _recordListArr.count + 1;
        }
        return _recordListArr.count;
    }
    else if(section == 4 && _isNeedHXBZ)//选择核销标准
    {
        return 2;
    }
    else if(section == 4 && _isShowHXBZ && _moduleType == HomeModuleTypeEA)//展示核销标准
    {
        return 1;
    }
    else if(section == 5 && _isShowHXBZ && _moduleType == HomeModuleTypeEC)//展示核销标准
    {
        return 1;
    }

    else
    {
        if (section == 2)
        {
            return _cargoListArr.count;
        }
 
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0000001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 50.0;
    }
    else if(section == 4 && _isShowHXBZ && _moduleType == HomeModuleTypeEA)//展示核销标准
    {
        return 50;
    }
    else if(section == 5 && _isShowHXBZ && _moduleType == HomeModuleTypeEC)//展示核销标准
    {
        return 50;
    }

    else
    {
        if (_moduleType == HomeModuleTypeEA)
        {
            if (section == 2)
            {
                return 50.0;
            }
        }
        else
        {
            if (section == 3)
            {
                return 50.0;
            }
        }
        return 0.00001;
    }
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(section == 1)
    {
        UIView *headView = [self createHeaderViewWithTitle:@"审批信息"];
        return headView;
    }
    else if(section == 4 && _isShowHXBZ && _moduleType == HomeModuleTypeEA)//展示核销标准
    {
        UIView *headView = [self createHeaderViewWithTitle:@"费用核销标准"];
        return headView;
    }
    else if(section == 5 && _isShowHXBZ && _moduleType == HomeModuleTypeEC)//展示核销标准
    {
        UIView *headView = [self createHeaderViewWithTitle:@"费用核销标准"];
        return headView;
    }
    else
    {
        if (_moduleType == HomeModuleTypeEA)
        {
            if (section == 2)
            {
                UIView *headView = [self createHeaderViewWithTitle:@"产品清单"];
                return headView;
            }
        }
        else
        {
            if (section == 3)
            {
                UIView *headView = [self createHeaderViewWithTitle:@"产品清单"];
                return headView;
            }
        }
        return nil;
    }
}

- (UIView *)createHeaderViewWithTitle:(NSString *)title
{
    UIView *headView = [UIView new];
    headView.backgroundColor = [UIColor whiteColor];
    UILabel *lab = [UILabel new];
    lab.text = title;
    lab.textColor = [UIColor blackColor];
    lab.font = KwFont(15);
    [headView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headView.mas_left).offset(20);
        make.top.equalTo(headView).offset(15);
        make.height.equalTo(@15);
    }];

    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(0, 50, self.view.bounds.size.width, 1.5);
    lineView.backgroundColor = KwGaryColor;
    [headView addSubview:lineView];
    return headView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *photoManageCell_ID = @"PhotoManageCell";
    static NSString *recordCell_ID = @"recordCellID";
    if (indexPath.section == 0)
    {
        LabTextViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"labTextFieldCell_ID%ld",indexPath.row]];
        if (!cell)
        {
            cell = [[LabTextViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"labTextFieldCell_ID%ld",indexPath.row]];
        }
        NSDictionary *dic = _detailInfoArr[indexPath.row];
        NSString *key = [dic allKeys][0];
        cell.constStr = key;
        cell.paraStr = [dic objectForKey:key];
//        cell.rightTxtF.text = [dic objectForKey:key];
        cell.rightTxtF.userInteractionEnabled = NO;
        return cell;
    }
    else if (indexPath.section == 1)
    {

        if (indexPath.row == _recordListArr.count) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"refuseCell"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"refuseCell"];
            }
            cell.textLabel.text = [NSString stringWithFormat:@"拒绝原因：%@", _detailModel.remarks];
            cell.textLabel.numberOfLines = 0;
            cell.textLabel.font = KwFont(14);
            cell.textLabel.textColor = [UIColor grayColor];
            return cell;
        }
        
        UITableViewCell *cell;
        cell = [tableView dequeueReusableCellWithIdentifier:recordCell_ID];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:recordCell_ID];
            if (_recordListArr && _recordListArr.count > 0)
            {
                EnterDetailCheckListModel *model = _recordListArr[indexPath.row];

                UILabel *firstLab = [UILabel new];
                firstLab.textColor = [UIColor grayColor];
                firstLab.numberOfLines = 0;
                firstLab.font = [UIFont systemFontOfSize:14.0];
                firstLab.textAlignment = NSTextAlignmentLeft;
                NSString *str = [NSString stringWithFormat:@"%@,%@,%@",model.userName,model.approvalTime,model.approvalMemo];
                firstLab.text = str;
                [cell addSubview:firstLab];
                [firstLab mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(@20);
                    make.right.equalTo(@-15);
                    make.top.equalTo(@10);
                    make.bottom.equalTo(@-15);
                }];
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if ( indexPath.section == 2)
    {
        CargoCell *cell;
        //其余为商品展示
        cell = [tableView dequeueReusableCellWithIdentifier:@"carCell"];
        if (!cell)
        {
            cell = [[CargoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"carCell"];
        }
        if (_cargoListArr.count > 0)
        {
            cell.saCargoModel = _cargoListArr[indexPath.row];
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else if(indexPath.section == 4 && _isNeedHXBZ &&  _moduleType == HomeModuleTypeEA)
    {
        if (indexPath.row == 0) {
            ChooseViewCell *cell;
            cell = [tableView dequeueReusableCellWithIdentifier:@"cellText"];
            if (!cell)
            {
                cell = [[ChooseViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellText"];
            }
            [cell setUpUIWithArr:_DataHXBZArr TextStr:@"" ChooseNumber:_tagNumber];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.reloadBtnBlock = ^(NSInteger tagNumber){
                
//                float oldheight =  [ToolViewViewController heightForTextViewWithText:_DataHXBZArr[_tagNumber][@"contents"]];
//                
                _tagNumber = tagNumber-100;
//                
//                float Newheight =  [ToolViewViewController heightForTextViewWithText:_DataHXBZArr[_tagNumber][@"contents"]];
//                
//                if (Newheight - oldheight > 0) {
//                    [_tabView mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.top.equalTo(@0);
//                        make.left.right.equalTo(@0);
//                        make.bottom.equalTo(@(-60-(Newheight - oldheight)));
//                    }];
//                }
//                
//                NSIndexSet *indeSec = [NSIndexSet indexSetWithIndex:4];
//                [_tabView reloadSections:indeSec withRowAnimation:UITableViewRowAnimationAutomatic];
//                
//                if (Newheight - oldheight > 0) {
//                    [_tabView mas_makeConstraints:^(MASConstraintMaker *make) {
//                        make.top.equalTo(@0);
//                        make.left.right.equalTo(@0);
//                        make.bottom.equalTo(@0);
//                    }];
//                }
                NSIndexSet *indeSec = [NSIndexSet indexSetWithIndex:4];
                [_tabView reloadSections:indeSec withRowAnimation:UITableViewRowAnimationAutomatic];
                
                [_tabView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:4] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                
            };
            return cell;
        }else
        {
            TextViewCell *cell;
            cell = [tableView dequeueReusableCellWithIdentifier:@"cellText2"];
            if (!cell)
            {
                cell = [[TextViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellText2"];
            }
            [cell setUpUIWithTextStr:_DataHXBZArr[_tagNumber][@"contents"]];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.reloadTextBlock = ^(UITextView *texView){
                [_DataHXBZArr[_tagNumber] setObject:texView.text forKey:@"contents"];
                btnsView.mbContent = _DataHXBZArr[_tagNumber][@"contents"];
            };

            return cell;
        }
    }
    else if(indexPath.section == 4 && _isShowHXBZ &&  _moduleType == HomeModuleTypeEA)
    {
        
        TextViewCell *cell;
        cell = [tableView dequeueReusableCellWithIdentifier:@"cellText2"];
        if (!cell)
        {
            cell = [[TextViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellText2"];
        }
        [cell setUpUIWithTextStr:_mbContect];
        cell.textView.editable = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if(indexPath.section == 5 && _isShowHXBZ &&  _moduleType == HomeModuleTypeEC)
    {
        
        TextViewCell *cell;
        cell = [tableView dequeueReusableCellWithIdentifier:@"cellText2"];
        if (!cell)
        {
            cell = [[TextViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellText2"];
        }
        [cell setUpUIWithTextStr:_mbContect];
        cell.textView.editable = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        PhotoManageCell *cell;
        cell = [tableView dequeueReusableCellWithIdentifier:photoManageCell_ID];
        if (!cell)
        {
            cell = [[PhotoManageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:photoManageCell_ID];
        }
        cell.vc = self;
        if (_moduleType == HomeModuleTypeEA)
        {
            cell.titleLabel.text = @"进场明细照片管理";
            [cell configCell:_scenePics];
            cell.picType = PicTypeEnterFeeApply_Enter;
        }
        else
        {
            if (indexPath.section == 3)
            {
                cell.titleLabel.text = @"进场明细照片管理";
                [cell configCell:_scenePics];
                cell.picType = PicTypeEnterFeeCheck_Enter;
            }
            else
            {
                cell.titleLabel.text = @"票据照片管理";
                [cell configCell:_paperPics];
                cell.picType = PicTypeEnterFeeCheck_Bill;
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.orderId = _orderId;
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (void)onTapLeftBarButton {
    [Singleton shareInstance].noRefresh = YES;
    [self.navigationController popViewControllerAnimated:YES];
}
@end

